package goldeneagle.com.admin.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;

import goldeneagle.com.admin.dao.impl.AdminManagerDaoImpl;
import goldeneagle.com.entity.User;
import goldeneagle.com.util.Page;

/**
 * Servlet implementation class AdminPageSelectUserServlet
 */
@WebServlet(value="/AdminPageSelectUserServlet")
public class AdminPageSelectUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminPageSelectUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int currentPage = (request.getParameter("currentPage")==null||request.getParameter("currentPage").equals(""))?1:Integer.parseInt(request.getParameter("currentPage"));
		AdminManagerDaoImpl ad = new AdminManagerDaoImpl();
		int count = (int)ad.totalCount("User");
		List<User> list = ad.adminSelectUserList(currentPage, 2);
		Page<User> page = new Page<User>(currentPage,2,list);
		page.setTotalCount(count);
		request.setAttribute("page",page);
		request.getRequestDispatcher("admin_userpage.jsp").forward(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
